package cn.arikeky.basic.aop;

import cn.arikeky.basic.anno.LogAnno;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.aspectj.lang.reflect.MethodSignature;
import org.springframework.stereotype.Component;

import java.lang.reflect.Method;

@Component
@Aspect
public class LogAop {

    @Pointcut("@annotation(cn.arikeky.basic.anno.LogAnno)")
    public void pointCut(){}


    @Around("pointCut()")
    public Object around(ProceedingJoinPoint pjp){
        // 获取到所有的方法
        MethodSignature signature = (MethodSignature) pjp.getSignature();
        Method method = signature.getMethod();
        LogAnno annotation = method.getAnnotation(LogAnno.class);
        String method1 = annotation.method();
        String methodDes = annotation.methodDes();


        // 执行业务方法
        Object proceed = null;
        try {
            proceed = pjp.proceed();
        } catch (Throwable throwable) {
            throwable.printStackTrace();
        }
        // 添加日志


        return proceed;
    }

}
